package com.fuxi.cloud.desreport.service.a;

import com.alibaba.fastjson.JSONArray;
import com.fuxi.cloud.desreport.dao.JimuReportDbParamDao;
import com.fuxi.cloud.desreport.entity.JmReportDb;
import com.fuxi.cloud.desreport.entity.JmReportDbParam;
import com.fuxi.cloud.desreport.service.IJmReportDbParamService;
import com.fuxi.cloud.desreport.service.IJmReportDbService;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.minidao.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * a
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
@Service("jmReportDbParamServiceImpl")
public class g implements IJmReportDbParamService {
    @Autowired
    @Lazy
    private IJmReportDbService jmReportDbService;
    @Autowired
    private JimuReportDbParamDao reportDbParamDao;

    public g() {
    }

    @Override
    public void deleteParamByIds(JSONArray deleteIds) {
        if (deleteIds != null && deleteIds.size() != 0) {
            ArrayList var2 = new ArrayList();

            for(int var3 = 0; var3 < deleteIds.size(); ++var3) {
                var2.add(deleteIds.getString(var3));
            }

            this.reportDbParamDao.deleteBatchIds(var2);
        }
    }

    @Override
    @Transactional(
            rollbackFor = {Exception.class}
    )
    public void deleteParamByIdsAndUpdateDbSql(JSONArray ids, String dbId, String dbDynSql) {
        this.deleteParamByIds(ids);
        JmReportDb var4 = new JmReportDb();
        var4.setId(dbId);
        var4.setDbDynSql(dbDynSql);
        this.jmReportDbService.updateById(var4);
    }

    @Override
    public void deleteByReportId(String reportId) {
        this.reportDbParamDao.deleteByReportId(reportId);
    }

    @Override
    public void saveOrUpdateBatch(List<JmReportDbParam> paramList) {
        Iterator var2 = paramList.iterator();

        while(var2.hasNext()) {
            JmReportDbParam var3 = (JmReportDbParam)var2.next();
            if (StringUtils.isNotEmpty(var3.getId())) {
                JmReportDbParam var4 = this.reportDbParamDao.get(var3.getId());
                if (null != var4) {
                    this.reportDbParamDao.update(var3);
                } else {
                    this.reportDbParamDao.insert(var3);
                }
            } else {
                var3.setId(String.valueOf(SnowflakeIdWorker.generateId()));
                this.reportDbParamDao.insert(var3);
            }
        }

    }

    @Override
    public List<JmReportDbParam> list(String jimuReportHeadId) {
        return this.reportDbParamDao.list(jimuReportHeadId);
    }
}

